Vue.component('v-select', VueSelect.VueSelect);
let createQuestionApp = new Vue({
    el:"#createQuestionApp",
    data:{
        title:'',
        tags:[],
        selectedTags:[],
        teachers:[],
        selectedTeachers:[],
        content:'12314515'
    },
    methods:{
        loadTags(){
            axios.get("/portal/tag/tags")
                .then(result => {
                    let r = result.data
                    if(r.code == OK){
                        for (let i = 0;i<r.data.length;i++)
                        this.tags.push(r.data[i].name)
                    }

                })
        },
        loadTeachers(){
            axios.get('/portal/user/teachers')
                .then(result=>{
                    let r = result.data
                    if(r.code == OK){
                        for (let i = 0; i < r.data.length; i++) {
                            this.teachers.push(r.data[i].nickname)
                        }
                    }
                })
        },
        createQuestion(){
            this.content = $("#summernote").val()
            let params = {title:this.title,selectedTags:this.selectedTags,selectedTeachers:this.selectedTeachers,content:this.content}
            axios.post('/portal/question/create', params)
                .then(result=>{
                    let r = result.data
                    console.log(r)
                    if(r.code == CREATED){
                        alert("发布成功")
                        location.href="/index.html"
                    }
                })
        }
    },
    created(){
        this.loadTags()
        this.loadTeachers()
    }
})